import request from '@/utils/request'
import type {
  addProjectParams,
  projectQueryParams,
} from '@/api/back-management/complete-community-project/interface'
import type { addProgressParams } from '@/api/back-management/complete-community-project/interface'
import type { Response, PageDataList } from '@/utils/type'
import type { AxiosResponse } from 'axios'

export interface ProjectDataResp {
  filingTime?: string
  pkid: string
  projectName: string
  investAmount?: string
  projectAddress: string
  projectType: string
  updateTime?: string
}

/**
 * 获取完整社区项目列表
 *
 * @param {projectQueryParams} params 查询参数
 */
export const queryProjectList = (
  params: projectQueryParams
): Promise<Response<PageDataList<ProjectDataResp>>> => {
  return request('/residential/basic/query', {
    method: 'GET',
    params,
  })
}

/**
 * 查询完整社区项目详情
 *
 * @param {string} pkid 主键id
 */
export const getProjectDetail = (pkid: string) => {
  return request('/residential/basic/get', {
    method: 'GET',
    params: {
      pkid,
    },
  }) as Promise<Response<any>>
}

/**
 * 新增完整社区项目
 *
 * @param {addProjectParams} params 新增参数
 */
export const addProject = (params: addProjectParams) => {
  return request('/residential/basic/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 删除完整社区项目
 *
 * @param {string} pkid 主键id
 */
export const deleteProject = (pkid: string) => {
  return request('residential/basic/delete', {
    method: 'DELETE',
    params: {
      pkid,
    },
  }) as Promise<Response<any>>
}

/**
 * 编辑完整社区项目
 *
 *
 * @param {addProjectParams} params 新增参数
 */
export const editProject = (params: addProjectParams) => {
  return request(`/residential/basic/update`, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 查询项目进展
 *
 * @param {string} projectId 项目id
 */
export const getProjectProgress = (projectId: string, stageType: string) => {
  return request('/residential/stage/get', {
    method: 'GET',
    params: {
      projectId,
      stageType,
    },
  }) as Promise<Response<any>>
}

/**
 * 新增项目进展
 *
 * @param {addProgressParams} params 新增参数
 */
export const addProjectProgress = (
  projectId: string,
  params: addProgressParams
) => {
  return request('/residential/stage/add?projectId=' + projectId, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 修改项目进展
 *
 *
 * @param {addProgressParams} params 新增参数
 */
export const editProjectProgress = (
  projectId: string,
  params: addProgressParams
) => {
  return request('/residential/stage/update?projectId=' + projectId, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 完整社区项目批量下载
 *
 * @basicId {string} basicId
 *
 */
export const downloadBasicList = (
  basicId: string
): Promise<AxiosResponse<Blob>> => {
  return request(`/residential/basic/exportExcel?basicId=${basicId}`, {
    responseType: 'blob',
  })
}
